home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / lftp / convert-netscape-cookies next >
Encoding:
Text File  |  2007-03-07  |  963 b   |  35 lines

  1. #!/usr/bin/perl
  2. # Copyright (c) 2001,2005 Alexander V. Lukyanov <lav@yars.free.net>
  3. # See COPYING file (GNU GPL) for complete license.
  4.  
  5. # This script converts netscape-style cookies to lftp set commands.
  6.  
  7. $file=$ARGV[0] if defined $ARGV[0];
  8. $file=qx{
  9.     ls -t \$HOME/.netscape/cookies \\
  10.           `find \$HOME/.mozilla -name cookies.txt` | head -1
  11. },chomp $file if !defined $file;
  12.  
  13. open COOKIES,"<$file" or die;
  14. print "# converted from $file\n";
  15. while(<COOKIES>)
  16. {
  17.    chomp;
  18.    next if /^#/ or /^$/;
  19.    s/"/\\"/g;
  20.    s/ /%20/g;
  21.    ($domain,undef,$path,$secure_bool,$expires,$name,$value)=split /\t/;
  22.    $secure='';
  23.    $secure=';secure' if $secure_bool eq 'TRUE';
  24.    $domain="*$domain" if $domain =~ /^\./;
  25.    $path='' if $path eq '/';
  26.    $path=";path=$path" if $path ne '';
  27.    $value="=$value" if $name ne '';
  28.    $cookie{"$domain$path$secure"}.=" $name$value";
  29. }
  30. foreach(sort keys %cookie)
  31. {
  32.    $cookie{$_}=~s/^ //;
  33.    print "set http:cookie/$_ \"$cookie{$_}\"\n";
  34. }
  35.